<template>
<div>
    <h1>康复理疗列表页</h1>
    项目名称
    <input type="text" v-model="dataPs.name">

    <input type="button" value="查询" @click="Show()">
    
    <input type="button" value="批量修改" @click="Upd">
    <a href="/KAdd">新增</a>

    <table class="table">
        <thead>
            <tr>
                <td><input type="checkbox" v-model="quan" @change="qx"></td>
                <td>项目名称</td>
                <td>项目编码</td>
                <td>佣金(元)</td>
                <td>服务人数</td>
                <td>服务时长</td>
                <td>项目说明</td>
                <td>状态</td>
                <td>操作</td>
            </tr>
        </thead>

        <tbody>
            <tr v-for="d in data">
                <td><input type="checkbox" v-model="fan" :value="d.id"></td>
                <td>{{d.kname}}</td>
                <td>{{d.kBma}}</td>
                <td>{{d.kMoney}}</td>
                <td>{{d.kcount}}</td>
                <td>{{d.kdate}}</td>
                <td>{{d.kMessage}}</td>
                <td>{{d.zt==1?'启用':'禁用'}}</td>
                <td>
                    <input type="button" value="删除" @click="Del(d.id)">
                </td>
            </tr>
        </tbody>
    </table>

一共{{pagedate.count}}条 每页{{dataPs.size}}条 一共{{pagedate.listcount}}页 当前第{{dataPs.index}}页

<input type="button" value="首页" @click="fenye(1)">
<input type="button" value="上一页" @click="fenye(2)">

<input type="button" v-for="d in pagedate.listcount" :value="d" @click="shuzi(d)">

<input type="button" value="下一页" @click="fenye(3)">
<input type="button" value="尾页" @click="fenye(4)">

<input type="number" v-model="dataPs.index"><input type="button" value="跳转" @click="tiao">

<select v-model="dataPs.size" @click="tiao1">
    <option value="1">1</option>
    <option value="3">3</option>
    <option value="5">5</option>
    <option value="7">7</option>
    <option value="9">9</option>
</select>


</div>

</template>

<script setup lang="ts">
import {ref,onMounted} from 'vue';
import axios from 'axios';
import { useRouter } from 'vue-router';
import moment from 'moment';
const router=useRouter()

onMounted(()=>{
    Show()
})

const quan=ref(false)
const fan=ref([])

const qx=()=>{
    if(quan.value){
        data.value.forEach(x=>{
            fan.value.push(x.id)
        })
    }else{
        fan.value=[]
    }
}

const Upd=(id:any)=>{
    if(!confirm("确认修改吗")){
        return
    }

    axios.get("/api/KangFu/UpdState",{params:{idstring:fan.value.toString()}}).then(res=>{
        if(res.data>0){
            alert("修改成功");
            Show()
        }else{
            alert("修改失败");
        }
    })
}

const data=ref([{
     "id": 3,
      "kname": "腿部训练",
      "kBma": "66611400-001",
      "kMoney": 977,
      "kcount": 3,
      "kdate": 4,
      "kMessage": "增强跑步发力速度",
      "zt": 1,
      "isDeleted": true
}])


const fenye=(val:any)=>{
    if(val==1){
        dataPs.value.index=1
    }
    if(val==2){
        if(dataPs.value.index>2){
            dataPs.value.index-=1
        }
    }
    if(val==3){
        if(dataPs.value.index<pagedate.value.listcount){
            dataPs.value.index+=1
        }
    }
    if(val==4){
        dataPs.value.index=pagedate.value.listcount
    }
    Show()
}

const shuzi=(val:any)=>{
    dataPs.value.index=val
    Show()
}

const tiao=(val:any)=>{
    if(dataPs.value.index>0&&dataPs.value.index<pagedate.value.listcount){
        Show()
    }else{
        Show()
    }
}

const tiao1=()=>{
    dataPs.value.index=1
    Show()
}


const dataPs=ref({
    name:"",
    index:1,
    size:3
})

const pagedate=ref({
    count:0,
    listcount:0
})


const Show=()=>{
    axios.get("/api/KangFu/KShow",{params:dataPs.value}).then(res=>{
        data.value=res.data.list

        pagedate.value.count=res.data.count
        pagedate.value.listcount=Math.ceil(pagedate.value.count/dataPs.value.size)
    })
}

const Del=(id:any)=>{
     if(!confirm("确认删除吗")){
        return
    }

    axios.delete("/api/KangFu/Delete",{params:{id:id}}).then(res=>{
        if(res.data>0){
            alert("删除成功");
            Show()
        }else{
            alert("删除失败");
        }
    })
}



        
</script>

<style lang="scss" scoped>

</style>